package com.pj.project.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pj.project.model.mapper.SpGoodsSortMapper;
import com.pj.project.model.mapper.SpGoodsWarehouseMapper;
import com.pj.project.model.pojo.SpGoodsDetail;
import com.pj.project.model.vo.SpGoodsDetailVO;
import com.pj.project.service.SpGoodsDetailService;
import com.pj.project.model.mapper.SpGoodsDetailMapper;
import com.pj.utils.so.SoMap;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author hanwu
 * @description 针对表【sp_goods_detail(物品详情表)】的数据库操作Service实现
 * @createDate 2023-01-26 12:19:33
 */
@Service
public class SpGoodsDetailServiceImpl extends ServiceImpl<SpGoodsDetailMapper, SpGoodsDetail>
        implements SpGoodsDetailService {

    @Resource
    SpGoodsDetailMapper goodsDetailMapper;

    @Resource
    SpGoodsSortMapper goodsSortMapper;

    @Resource
    SpGoodsWarehouseMapper goodsWarehouseMapper;

    /**
     * 查询列表
     */
    @Override
    public List<SpGoodsDetailVO> getList(SoMap so) {
        List<SpGoodsDetail> list = goodsDetailMapper.getList(so.startPage());
        //        创建vo对象
        List<SpGoodsDetailVO> GoodsDetailVOList = new ArrayList<>();
        for (SpGoodsDetail spGoodsDetail : list) {
            SpGoodsDetailVO goodsDetailVO = new SpGoodsDetailVO();
//                拷贝对象
            BeanUtils.copyProperties(spGoodsDetail, goodsDetailVO);
            goodsDetailVO.setSortName(goodsSortMapper.selectByIdForName(spGoodsDetail.getSortId()));
            goodsDetailVO.setWarehouseName(goodsWarehouseMapper.selectByIdForName(spGoodsDetail.getWarehouseId()));
            GoodsDetailVOList.add(goodsDetailVO);
        }
        return GoodsDetailVOList;
    }
}




